﻿using ldhWebApiWF.database;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Cors;

namespace ldhWebApiWF.Controller
{
    // Allow CORS for all origins. (Caution!)
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    //[EnableCors(origins: "http://www.contoso.com,http://www.example.com", headers: "accept,content-type,origin,x-my-header", methods: "get,post")]
    [RoutePrefix("api1")]
    public class ValuesController : ApiController
    {
        //IMongoCollection<BsonDocument> books;

        //public ValuesController()
        //{
        //    books = BaseManager.GetClient<BsonDocument>("Bookdb", "Books");
        //}

        // GET api/values 
        //[DeflateCompression]//using zlib compression
        [HttpGet]
        [Route("a")]
        public async Task<string> GetHello()
        {
            return await Task.Run(() => { return "hello world"; });
        }

        //// GET api/values/5 
        ////[ResponseType(typeof(Book))]
        //[HttpGet]
        //[Route("checkkeys/{id}")]
        //public async Task<IHttpActionResult> GetTest(int id)
        //{
        //    var data = books.Find(new BsonDocument()).First();
        //    if (data.Names.ContainsAll(new List<string>() { "Genre", "ReleaseDate" }))
        //    {
        //        return Ok(new string[] { "value1", "value2" });
        //    }
        //    await Task.Delay(20);
        //    return Ok(new string[] { "No1", "No2" });
        //}

        //// POST api/values 
        //[Route("values")]
        //public void Post([FromBody]string value)
        //{
        //}

        //// PUT api/values/5 
        //public void Put(int id, [FromBody]string value)
        //{
        //}

        //// DELETE api/values/5 
        //public void Delete(int id)
        //{
        //}
    } 
}
